<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var sortColors = function (nums) {
      let num0 = 0, num1 = 0, num2 = 0;
      for (let i = 0; i < nums.length; i++) {
        nums[i] === 0 ? num0++ : nums[i] === 1 ? num1++ : num2++;
      }
      for (let i = 0; i < num0; i++) {
        nums[i] = 0;
      }
      for (let i = num0; i < num1 + num0; i++) {
        nums[i] = 1;
      }
      for (let i = num0 + num1; i < num0 + num1 + num2; i++) {
        nums[i] = 2;
      }
      return nums;
    };
    console.log(sortColors([2, 0, 2, 1, 1, 0]));
  </script>
</body>

</html>